#!/bin/env python
#
# Copyright 2009 Timo Peter Becker
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


from waveapi import events
from waveapi import model
from waveapi import robot

def OnBlipSubmitted(properties, context):
	# This event handler is called when someone submits a blib
	
	blip = context.GetBlipById(properties['blipId'])
	doc=blip.GetDocument()
	contents = doc.GetText()
	contents = contents.replace('a','4')
	contents = contents.replace('e','3')
	contents = contents.replace('l','1')
	contents = contents.replace('o','0')
	contents = contents.replace('s','5')
	contents = contents.replace('t','7')
	contents = contents.replace('z','2')
	contents = contents.replace('7h3','teh')
	contents = contents.replace('c001','k3wl')
	contents = contents.replace('!','!1!!ONEELEVEN')
	doc.SetText(contents)


if __name__ == '__main__':
	# main event handler initializes the robot
	
	myRobot = robot.Robot('l33tbert', 
	image_url='http://l33tbert.appspot.com/assets/icon.png', version='8', profile_url='http://l33tbert.appspot.com')
	myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
	myRobot.Run()